package org.easy.tencsms;

import com.github.qcloudsms.SmsSingleSender;

/**
 * 类描述：
 *
 * @date 2022-03-30
 */
public class QCloudsmsServiceImpl implements QCloudsmsService {

    private final Integer appid;
    private final String key;

    public QCloudsmsServiceImpl(Integer appid, String key) {
        this.appid = appid;
        this.key = key;
    }

    @Override
    public boolean sendSmsCode(SmsParamsDto smsParamsDto) {
        try {
            //短信模版号
            int templateId = Integer.parseInt(smsParamsDto.getTemplate());
            //签名
            String smsSign = smsParamsDto.getSign();
            //初始化单发
            SmsSingleSender singleSender = new SmsSingleSender(appid, key);

            singleSender.sendWithParam(smsParamsDto.getCode(), smsParamsDto.getPhone(), templateId, smsParamsDto.getParams(), smsSign, "", "");
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
}
